//
//  Person+AddProperty.m
//  RuntimeDemo
//
//  Created by zxs on 2021/2/24.
//

#import "Person+AddProperty.h"
#import <objc/runtime.h>

// 关联对象key
static NSString *heightKey = @"height";
static NSString *careerKey = @"career";
static NSString *locationKey = @"location";

@implementation Person (AddProperty)

#pragma mark - setter/getter
// 身高
- (void)setHeight:(NSInteger)height {
    objc_setAssociatedObject(self, &heightKey, @(height), OBJC_ASSOCIATION_ASSIGN);
}

- (NSInteger)height {
    NSNumber *heightValue = objc_getAssociatedObject(self, &heightKey);
    return [heightValue integerValue];
}

// 职业
- (void)setCareer:(NSString *)career {
    objc_setAssociatedObject(self, &careerKey, career, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (NSString *)career {
    return objc_getAssociatedObject(self, &careerKey);
}

// 位置
- (void)setLocation:(CGPoint)location {
    NSValue *locationValue = [NSValue valueWithCGPoint:location];
    objc_setAssociatedObject(self, &locationKey, locationValue, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (CGPoint)location {
    NSValue *locationValue = objc_getAssociatedObject(self, &locationKey);
    return [locationValue CGPointValue];
}

@end
